ListNode* deleteDuplicates(ListNode* head) {
    ListNode* p;
    ListNode* q;
    p = head;
    while (p != nullptr && p->next != nullptr) {
        if (p->val == p->next->val) {
            ListNode* temp;
            temp = p->next;
            p->next = temp->next;
            free(temp);
        }
        else {
            p = p->next;
        }
    }
    return head;
}